﻿@model CREAPA.Dominio.Portaria
@{
    ViewBag.Title = "Pesquisa de Portaria";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<style>
		
		* {
			margin: 0;
			padding: 0;
		}

        fieldset.grupo {
			border: 0;
		}

		
		body, input, select, textarea, button {
			font-family: sans-serif;
			font-size: 1em;
		}

		.grupo:after {
			content: "."; 
			display: block; 
			height: 0;
			clear: both; 
			visibility: hidden;
		}

		.campo {
			margin-bottom: 1em;
		}
        
        .campo label {
			margin-bottom: 0.2em;
			color: #000;
			display: block;
            margin-left: 3px;
		}

		fieldset.grupo .campo {
			float: left;
			margin-right: 3em;
            margin-left: 3px;
		}

		.campo input[type="text"],
		.campo input[type="email"],
		.campo input[type="url"],
		.campo input[type="tel"] {
			padding: 0.2em;
			border: 1px solid #CCC;
			box-shadow: 2px 2px 2px rgba(0,0,0,0.2);
			display: block;
            width: 200%;
            margin-left: 3px;
		}
        .campo textarea {
			padding: 0.2em;
			border: 1px solid #CCC;
			box-shadow: 2px 2px 2px rgba(0,0,0,0.2);
			display: block;
            width: 525px;
            margin-left: 3px;
		}

		.campo select option {
			padding-right: 1em;
		}

		.campo input:focus, .campo select:focus, .campo textarea:focus {
			background: #ffffff;
		}

		.campo label.checkbox {
			color: #000;
			display: inline-block;
			margin-right: 1em;
		}
	
	</style>

<script>
jQuery(document).ready(function() {
  // verifica se existe algum elemento com a class
    if ($(".button").length) {
    // adiciona evento desabilitando o botão
        $(".button").on('click', function () {
            $(this).attr({
                disabled: true
         });
      // descobrindo o form pai e enviando
             this.value ='Pesquisando...';
            $(this).parents('form:first').submit();
    });
  }
});
</script>

@{    
    var grid = new WebGrid(ViewBag.ListaDePortaria, rowsPerPage: 500); 
}

<h2>Pesquisa de Portaria</h2>

@using (Html.BeginForm("Pesquisar", "Portaria", FormMethod.Post,
          new { enctype = "multipart/form-data" }))
{
 @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)
   
    <fieldset>
        <legend> Portaria </legend>   

        <fieldset class="grupo"> 
        
        <div  style="width: 50px;">
        <div class="campo">                        
                Número:
            @Html.EditorFor(model => model.Numero)
            </div>
        </div>
        </fieldset>

        <fieldset class="grupo"> 
        <div class="campo">
            Ano:
            @Html.DropDownListFor(model => model.Ano,
                      new SelectList(new List<SelectListItem> {
                      new SelectListItem{Value=@DateTime.Now.Year.ToString(), Text=@DateTime.Now.Year.ToString()},                           
                      new SelectListItem{Value=(@DateTime.Now.Year-1).ToString(), Text=(@DateTime.Now.Year-1).ToString()}},                           
                                         "Value", "Text"))
        </div>           
        </fieldset>

         <fieldset class="grupo"> 
        
        <div  style="width: 90px;">
        <div class="campo">                        
            Data:
            @Html.EditorFor(model => model.DataPortaria)
            </div>
        </div>
        </fieldset>
       
       <fieldset class="grupo"> 
        
        <div class="campo">
            Tipo de Portaria:
            @Html.DropDownList("IdTipoPortaria", "Selecione")
            @Html.ValidationMessageFor(model => model.IdTipoPortaria)
        </div>

           </fieldset> 
         <fieldset class="grupo"> 
        <div class="campo">
            Assunto:
            @Html.DropDownList("IdAssuntoPortaria", "Selecione")
            @Html.ValidationMessageFor(model => model.IdAssuntoPortaria)
</div>       
        </fieldset>
       <br />

        </fieldset> 
        <p>
            <input type="submit" value="Pesquisar" class="button"/>
            @Html.ActionLink("Voltar", "Index", null, new { @class = "button2" })
        </p>
   



    if (ViewBag.ListaDePortaria.Count > 0)
    {
     @*var grid = new WebGrid(ViewBag.ListaDePortaria, canPage: true, defaultSort: "Descricao", rowsPerPage: 500);*@ 
        <div id="grid" >
        @grid.GetHtml(tableStyle: "table",
        alternatingRowStyle: "alternate",
        headerStyle: "header",
        footerStyle: "footer",
        mode: WebGridPagerModes.FirstLast | WebGridPagerModes.NextPrevious,
        firstText: "Primeiro",
        previousText: "Anterior",
        nextText: "Próximo",
        lastText: "Último",
    columns:
        grid.Columns(
            grid.Column("Id", header: "Requisição", format: @<center><text>@item.Id</text></center>),
              grid.Column("Numero", header: "Número", format: @<center><text>@item.Numero</text></center>),
              grid.Column("Ano", header: "Ano", format: @<center><text>@item.Ano</text></center>),
              grid.Column("DataPortaria", header: "DataPortaria", format: @<center><text>@item.DataPortaria</text></center>),
              grid.Column("PessoaCadastrou", header: "Solicitante", format: @<center><text>@item.PessoaCadastrou</text></center>),
              grid.Column("TipoPortaria", header: "TipoPortaria", format: @<center><text>@item.IdTipoPortaria</text></center>),
              grid.Column("Assunto", header: "Assunto", format: @<center><text>@item.IdAssuntoPortaria</text></center>),
              grid.Column("Imprimir", header: "Imprimir", format: @<text><center>@Html.ActionLink("Imprimir", "ImprimirPortaria", new { id = item.Id }, new { target = "_blank" })</center></text>),
              grid.Column("Ver", header: "Ver", format: @<text><center>@Html.ActionLink("Ver", "Detalhes", new { id = item.Id })</center></text>)
));
</div>
    }else {
    if( TempData["aux"] == "vazio"){
        <p>Nenhum resultado encontrado</p>
    }
}

}

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

